home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / number.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.8 KB  |  103 lines

  1. // $Id: number.cc 1.3 1997/07/14 04:23:01 dlorre Exp dlorre $
  2. #include <exec/lists.h>
  3. #include <intuition/imageclass.h>
  4. #include <intuition/gadgetclass.h>
  5. #include <libraries/gadtools.h>
  6. #include <mydebug.h>
  7.  
  8. #include "gadgets/number.h"
  9. #include "gadgetlist.h"
  10. #include "window.h"
  11. #include "screen.h"
  12.  
  13.  
  14. // ========================================================================
  15. // ==========================  NUMBER CLASS ===============================
  16. // ========================================================================
  17.  
  18. number::number(gadgetlist *gl,
  19.                void (window::*func)(gadget *, unsigned long, unsigned short),
  20.                const char *title,
  21.                long val,
  22.                long max,
  23.                unsigned long flags,
  24.                unsigned long justify) : gadget(gl, func)
  25. {
  26. long pens, apens ;
  27.  
  28.     pens = apens = gl->win->ws->xpens[BLACK_PEN] << 8 ;
  29.     pens += gl->win->ws->xpens[WHITE_PEN] ;
  30.     apens += gl->win->ws->xpens[GREEN_PEN] ;
  31.  
  32.     gl->ng->ng_GadgetText = (UBYTE *)title ;
  33.     underkey(title) ;
  34.     gl->ng->ng_Flags = flags ;
  35.  
  36.     // since the font style can be modified several times
  37.     // in a window opening process, this is a reliable way to be sure
  38.     // that the wanted font will be used
  39.  
  40.     gfont = OpenFont(gl->ng->ng_TextAttr) ;
  41.  
  42.     im = (Image *)NewObject(NULL, (UBYTE *)"frameiclass",
  43.         IA_Top,             -1,
  44.         IA_Left,            -2,
  45.         IA_Width,           gl->ng->ng_Width,
  46.         IA_Height,          gl->ng->ng_Height,
  47.         IA_Recessed,        TRUE,
  48.         TAG_DONE) ;
  49.  
  50.     gad = gl->gad = (Gadget *)NewObject(NULL, (UBYTE *)"strgclass",
  51.             GA_Top,                 gl->ng->ng_TopEdge+1,
  52.             GA_Left,                gl->ng->ng_LeftEdge+2,
  53.             GA_Width,               gl->ng->ng_Width-4,
  54.             GA_Height,              gl->ng->ng_Height-2,
  55.             GA_ID,                  id,
  56.             GA_Image,               im,
  57.  
  58.             GA_RelVerify,           TRUE,
  59.  
  60.             GA_Previous,            gl->gad,
  61.             GA_TabCycle,            TRUE,
  62.  
  63.             STRINGA_MaxChars,       15,
  64.             STRINGA_LongVal,        val,
  65.             STRINGA_Pens,           pens,
  66.             STRINGA_ActivePens,     apens,
  67.             STRINGA_Justification,  justify,
  68.             STRINGA_Font,           gfont,
  69.  
  70.             TAG_END) ;
  71.  
  72.     curval = val ;
  73. }
  74.  
  75. number::~number()
  76. {
  77.     if (gad) DisposeObject(gad) ;
  78.     if (im) DisposeObject(im) ;
  79.     if (gfont) CloseFont(gfont) ;
  80. }
  81.  
  82. void number::action(unsigned long classe, unsigned short code)
  83. {
  84.     curval = ((StringInfo *)gad->SpecialInfo)->LongInt ;
  85.     gadget::action(classe, code) ;
  86. }
  87.  
  88. void number::set(long val)
  89. {
  90.     curval = val ;
  91.     SetGadgetAttrs(gad, w, NULL,
  92.         STRINGA_LongVal,    val,
  93.         TAG_END) ;
  94.  
  95. }
  96.  
  97.  
  98. void number::keystroke(BOOL shifted)
  99. {
  100.     ActivateGadget(gad, w, NULL) ;
  101. }
  102.  
  103.